#!/bin/bash

newvol="pkill -RTMIN+10 i3blocks"
newplayer="pkill -RTMIN+3 i3blocks"
newsong="pkill -RTMIN+4 i3blocks"

notify() {
    VOLUME=$(pamixer --get-volume)
    notify-send.py -t 1000 -r 0 --replaces-process "volumeID" -u normal -a "volume" "Volume level" " 🔊 ${VOLUME} %"
}


case "$1" in
    "up") pamixer -i "$2" ; $newvol ; notify  ;;
    "down") pamixer -d "$2" ; $newvol  ; notify ;;
    "mute") pamixer --allow-boost -t ; $newvol ; notify ;;
    "truemute") pamixer --allow-boost -m && $newsong; $newvol ;;
    "toggle") playerctl play-pause && $newplayer && $newsong;;
    "pause") playerctl pause  && $newplayer && $newsong;;
    "forward") playerctl position "$2"+ && $newplayer ;;
    "back") playerctl position "$2"- && $newplayer ;;
    "next") playerctl next && $newsong ;;
    "prev") playerctl previous && $newsong ;;
    "replay") playerctl previous && playerctl next && $newsong  ;;
esac
